# Maintainer: Martell Malone <martell malone at g mail dot com>
# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=cmake
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r34693.baf3c076f7
pkgrel=1
pkgdesc="A cross-platform open-source make system (mingw-w64)"
arch=('any')
url="https://www.cmake.org/"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-qt5-static"
             "git")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-winpthreads"
        "${MINGW_PACKAGE_PREFIX}-curl"
        #"${MINGW_PACKAGE_PREFIX}-expat"
        "${MINGW_PACKAGE_PREFIX}-libarchive"
        "${MINGW_PACKAGE_PREFIX}-ncurses"
        "${MINGW_PACKAGE_PREFIX}-pkg-config"
        "${MINGW_PACKAGE_PREFIX}-zlib"
        "${MINGW_PACKAGE_PREFIX}-libuv")
options=('staticlibs' '!strip' 'debug')
source=("${_realname}"::"git+https://cmake.org/cmake.git"
        '0001-Windows-Add-missing-stringapiset.h-include.patch'
        '0002-bootstrap-Set-DEFAULT_CODEPAGE-in-cmake_cxx_flags_En.patch'
        '0003-Disable-response-files-for-MSYS-Generator.patch'
        '0004-Implement-Qt5-static-plugin-support.patch'
        '0005-Output-line-numbers-in-callstacks.patch')
sha256sums=('SKIP'
            'fc26cb648fe3a731eee1a2ffa7269f5a3d23cb5cfda81e726512c2985b5955c7'
            '8afc3980d64858a2098f39d3497a8764986f7a37307f2c2e57645e6f4959f31a'
            '7f6d0cd97015d2cf04afc08680f028c323f535b9291f082a77c4a2a75eddd236'
            'c55be62cc2ead895d882db82ef475b60fa7a0d793b7580286cbfc1d60f124395'
            '8145bf666ebb3b8f461ac95df4b59f6b80bb4115bfa66b5673e1503da4d0f83b')

pkgver() {
  cd "$srcdir/$_realname"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${_realname}
  gitam_mkpkg "${srcdir}"/0001-Windows-Add-missing-stringapiset.h-include.patch
  gitam_mkpkg "${srcdir}"/0002-bootstrap-Set-DEFAULT_CODEPAGE-in-cmake_cxx_flags_En.patch
  gitam_mkpkg "${srcdir}"/0003-Disable-response-files-for-MSYS-Generator.patch
  gitam_mkpkg "${srcdir}"/0004-Implement-Qt5-static-plugin-support.patch
  gitam_mkpkg "${srcdir}"/0005-Output-line-numbers-in-callstacks.patch
}

build() {
  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"

# Not working yet ..
#  PATH=${MINGW_PREFIX}/qt5-static/bin:$PATH \

    MSYSTEM=MINGW "${srcdir}"/${_realname}/configure \
      --prefix=${MINGW_PREFIX} \
      --system-libs \
      --no-system-expat \
      --no-system-librhash \
      --qt-qmake=$(cygpath -m ${MINGW_PREFIX})/qt5-static/bin/qmake.exe \
      --no-qt-gui \
      --parallel=${NUMBER_OF_PROCESSORS} \
      --mandir=share \
      --docdir=share/doc/cmake

  plain "Start building..."
  make VERBOSE=1
}

package() {
  cd "${srcdir}/build-${CARCH}"
  ./bin/cmake.exe -DCMAKE_INSTALL_PREFIX:PATH=${pkgdir}${MINGW_PREFIX} -P cmake_install.cmake
}

# .. qt5-static stuff ..
# E:/m2/repo/mingw-w64-cmake-git/src/cmake/Source/QtDialog/CMakeLists.txt(159):  target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${CMake_QT_LIBRARIES} )
# /E/m2/repo/mingw-w64-cmake-git/src/build-x86_64/Bootstrap.cmk/cmake.exe -E cmake_depends "MSYS Makefiles" /E/m2/repo/mingw-w64-cmake-git/src/cmake /E/m2/repo/mingw-w64-cmake-git/src/cmake/Source/QtDialog /E/m2/repo/mingw-w64-cmake-git/src/build-x86_64 /E/m2/repo/mingw-w64-cmake-git/src/build-x86_64/Source/QtDialog /E/m2/repo/mingw-w64-cmake-git/src/build-x86_64/Source/QtDialog/CMakeFiles/cmake-gui.dir/DependInfo.cmake --color=
# make -f Source/QtDialog/CMakeFiles/cmake-gui.dir/build.make Source/QtDialog/CMakeFiles/cmake-gui.dir/build
# cd /E/m2/repo/mingw-w64-cmake-git/src/build-x86_64/Source/QtDialog && /E/msys64t/mingw64/bin/g++.exe  -march=x86-64 -mtune=generic -O2 -pipe  -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W -Wshadow -Wpointer-arith -Wformat-security -Wundef -fPIC   -pipe -mwindows -Wl,--whole-archive CMakeFiles/cmake-gui.dir/objects.a -Wl,--no-whole-archive  -o ../../bin/cmake-gui.exe -Wl,--out-implib,../../bin/libcmake-gui.dll.a -Wl,--major-image-version,0,--minor-image-version,0  ../libCMakeLib.a /E/msys64t/mingw64/qt5-static/lib/libqtmain.a /E/msys64t/mingw64/qt5-static/lib/libQt5Widgets.a ../kwsys/libcmsys.a -lPsapi ../../Utilities/cmexpat/libcmexpat.a /E/msys64t/mingw64/lib/libz.dll.a /E/msys64t/mingw64/lib/libarchive.dll.a ../../Utilities/cmcompress/libcmcompress.a /E/msys64t/mingw64/lib/libcurl.dll.a /E/msys64t/mingw64/lib/libjsoncpp.a -lrpcrt4 /E/msys64t/mingw64/qt5-static/lib/libQt5Gui.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqdds.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqicns.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqico.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqjp2.a -ljasper /E/msys64t/mingw64/qt5-static/share/qt5/plugins/platforms/libqminimal.a -lQt5PlatformSupport -lQt5DBus -lnetapi32 -lqtfreetype /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqmng.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/platforms/libqoffscreen.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqtga.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqtiff.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/generic/libqtuiotouchplugin.a -lQt5Network -ldnsapi -lssl -lcrypto -lcrypt32 /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqwbmp.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqwebp.a -lwebp /E/msys64t/mingw64/qt5-static/share/qt5/plugins/platforms/libqwindows.a -lwinspool -lshlwapi -lQt5PlatformSupport -lQt5DBus -lnetapi32 -lqtfreetype /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqmng.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/platforms/libqoffscreen.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqtga.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqtiff.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/generic/libqtuiotouchplugin.a -lQt5Network -ldnsapi -lssl -lcrypto -lcrypt32 /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqwbmp.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqwebp.a -lwebp /E/msys64t/mingw64/qt5-static/share/qt5/plugins/platforms/libqwindows.a -lwinspool -lshlwapi /E/msys64t/mingw64/qt5-static/lib/libQt5Core.a -lws2_32 -static -L$[QT_INSTALL_LIBS] -lQt5Gui -lcomdlg32 -loleaut32 -limm32 -lwinmm -lglu32 -lopengl32 -lgdi32 -lqtharfbuzzng -lQt5Core -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmpr -lqtpcre -lshell32 -luser32 -lkernel32 -lmpr -lqtpcre -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
# [ 63%] [32m[1mLinking CXX executable ../../bin/cmake-gui.exe[0m
# cd /E/m2/repo/mingw-w64-cmake-git/src/build-x86_64/Source/QtDialog && /E/m2/repo/mingw-w64-cmake-git/src/build-x86_64/Bootstrap.cmk/cmake.exe -E remove -f CMakeFiles/cmake-gui.dir/objects.a
# cd /E/m2/repo/mingw-w64-cmake-git/src/build-x86_64/Source/QtDialog && /E/msys64t/mingw64/bin/ar.exe cr CMakeFiles/cmake-gui.dir/objects.a "CMakeFiles/cmake-gui.dir/AddCacheEntry.cxx.obj" "CMakeFiles/cmake-gui.dir/CMakeSetup.cxx.obj" "CMakeFiles/cmake-gui.dir/CMakeSetupDialog.cxx.obj" "CMakeFiles/cmake-gui.dir/FirstConfigure.cxx.obj" "CMakeFiles/cmake-gui.dir/QCMake.cxx.obj" "CMakeFiles/cmake-gui.dir/QCMakeCacheView.cxx.obj" "CMakeFiles/cmake-gui.dir/QCMakeWidgets.cxx.obj" "CMakeFiles/cmake-gui.dir/moc_AddCacheEntry.cpp.obj" "CMakeFiles/cmake-gui.dir/moc_Compilers.cpp.obj" "CMakeFiles/cmake-gui.dir/moc_CMakeSetupDialog.cpp.obj" "CMakeFiles/cmake-gui.dir/moc_FirstConfigure.cpp.obj" "CMakeFiles/cmake-gui.dir/moc_QCMake.cpp.obj" "CMakeFiles/cmake-gui.dir/moc_QCMakeCacheView.cpp.obj" "CMakeFiles/cmake-gui.dir/moc_QCMakeWidgets.cpp.obj" "CMakeFiles/cmake-gui.dir/qrc_CMakeSetup.cpp.obj" "CMakeFiles/cmake-gui.dir/CMakeSetup.rc.obj"
# cd /E/m2/repo/mingw-w64-cmake-git/src/build-x86_64/Source/QtDialog && /E/msys64t/mingw64/bin/g++.exe  -march=x86-64 -mtune=generic -O2 -pipe  -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W -Wshadow -Wpointer-arith -Wformat-security -Wundef -fPIC   -pipe -mwindows -Wl,--whole-archive CMakeFiles/cmake-gui.dir/objects.a -Wl,--no-whole-archive  -o ../../bin/cmake-gui.exe -Wl,--out-implib,../../bin/libcmake-gui.dll.a -Wl,--major-image-version,0,--minor-image-version,0  ../libCMakeLib.a /E/msys64t/mingw64/qt5-static/lib/libqtmain.a /E/msys64t/mingw64/qt5-static/lib/libQt5Widgets.a ../kwsys/libcmsys.a -lPsapi ../../Utilities/cmexpat/libcmexpat.a /E/msys64t/mingw64/lib/libz.dll.a /E/msys64t/mingw64/lib/libarchive.dll.a ../../Utilities/cmcompress/libcmcompress.a /E/msys64t/mingw64/lib/libcurl.dll.a /E/msys64t/mingw64/lib/libjsoncpp.a -lrpcrt4 /E/msys64t/mingw64/qt5-static/lib/libQt5Gui.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqdds.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqicns.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqico.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqjp2.a -ljasper /E/msys64t/mingw64/qt5-static/share/qt5/plugins/platforms/libqminimal.a -lQt5PlatformSupport -lQt5DBus -lnetapi32 -lqtfreetype /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqmng.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/platforms/libqoffscreen.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqtga.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqtiff.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/generic/libqtuiotouchplugin.a -lQt5Network -ldnsapi -lssl -lcrypto -lcrypt32 /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqwbmp.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqwebp.a -lwebp /E/msys64t/mingw64/qt5-static/share/qt5/plugins/platforms/libqwindows.a -lwinspool -lshlwapi -lQt5PlatformSupport -lQt5DBus -lnetapi32 -lqtfreetype /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqmng.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/platforms/libqoffscreen.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqtga.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqtiff.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/generic/libqtuiotouchplugin.a -lQt5Network -ldnsapi -lssl -lcrypto -lcrypt32 /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqwbmp.a /E/msys64t/mingw64/qt5-static/share/qt5/plugins/imageformats/libqwebp.a -lwebp /E/msys64t/mingw64/qt5-static/share/qt5/plugins/platforms/libqwindows.a -lwinspool -lshlwapi /E/msys64t/mingw64/qt5-static/lib/libQt5Core.a -lws2_32 -static -L$[QT_INSTALL_LIBS] -lQt5Gui -lcomdlg32 -loleaut32 -limm32 -lwinmm -lglu32 -lopengl32 -lgdi32 -lqtharfbuzzng -lQt5Core -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmpr -lqtpcre -lshell32 -luser32 -lkernel32 -lmpr -lqtpcre -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
#
# -L$[QT_INSTALL_LIBS] seems to be missing something.
